//
//  OrdersTableViewCell.swift
//  DiDiRecycle
//
//  Created by abb on 16/7/15.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class OrdersTableViewCell: UITableViewCell {
    
    /// 订单模型
    var order:Order? {
        didSet {
            if order != nil {
                // 设置订单号
                orderIDLabel.text = "订单号: \(order!.id)"
                // 设置日期
                dateLabel.text = "预约时间: " + NSDate.StrFromTimeStamp(timestamp: order!.arrangeTime)
                // 设置图片
//                imageview.sd_setImageWithURL(order!.uipicture?.url)
                
                // 设置标题
                titleLabel.text = order!.name
                // 设置订单状态
                changeStatusLabel(order!.status)
                
            }
        }
    }
    private func changeStatusLabel(status:Int) {
        switch status {
        case 0:
            statusLabel.text = "已提交"
        case 1:
            statusLabel.text = "已预约"
        case 2:
            statusLabel.text = "已完成,待确认"
        case 3:
            statusLabel.text = "已结束"
        default:
            statusLabel.text = "未知"
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundView = UIImageView(image: UIImage(named: "tableviewCellBg")!)
        setupUI()
    }
    
    private func setupUI() {
        // 1.添加子控件
        addSubview(orderIDLabel)
        addSubview(dateLabel)
        addSubview(imageview)
        addSubview(titleLabel)
        addSubview(statusLabel)
        // 2.布局子控件
       orderIDLabel.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(10)
            make.left.equalTo(self).offset(20)
        }
        dateLabel.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(10)
            make.right.equalTo(self).offset(-20)
        }
        imageview.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.left.equalTo(self).offset(20)
            make.size.equalTo(CGSize(width: 70, height: 70))
            
            
        }
        titleLabel.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.left.equalTo(imageview.snp_right).offset(20)
        }
        statusLabel.snp_makeConstraints { (make) in
            make.bottom.right.equalTo(self).offset(-20)
        }
    }
    
    // MARK: - 懒加载
    /// 订单号
    private lazy var orderIDLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 12)
        label.text = "订单号:"
        return label
    }()
    /// 日期
    private lazy var dateLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 12)
        label.textAlignment = NSTextAlignment.Right
        return label
    }()
    /// 图片
    private lazy var imageview:UIImageView = {
        let iv = UIImageView()
        
        return iv
    }()
    /// 标题
    private lazy var titleLabel:UILabel = {
        let label = UILabel()
        
        return label
    }()
    /// 订单状态
    private lazy var statusLabel:UILabel = {
        let label = UILabel()
        
        return label
    }()
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

